package com.tsd.job.sample;

import com.alibaba.fastjson.JSON;
import com.tsd.core.datasource.SpringContextUtil;
import com.tsd.job.entity.SysTaskJobExt;
import com.tsd.job.service.SysTaskJobService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.List;

public class MyJob extends QuartzJobBean {

    @Override
    public void executeInternal(JobExecutionContext context) throws JobExecutionException {
        Scheduler scheduler = context.getScheduler();
        String jobName = context.getJobDetail().getKey().getName();
        String jobGroup = context.getJobDetail().getKey().getGroup();
        try {
            System.out.println("执行定时任务:MyJob.execute()...定时任务列表");
            SysTaskJobService sysTaskJobService = (SysTaskJobService) SpringContextUtil.getBean("sysTaskJobServiceImpl");
            List<SysTaskJobExt> list = sysTaskJobService.findAllEnable();
            System.out.println(JSON.toJSONString(list));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
